package com.ucampus.dao;

import org.apache.ibatis.annotations.*;

@Mapper
public interface VerificationCodeMapper {

    // 插入验证码
    @Insert("INSERT INTO verification_code (userPhone, code, created_at) VALUES (#{userPhone}, #{code}, NOW())")
    void insertCode(@Param("userPhone") String userPhone, @Param("code") String code);

    // 更新验证码
    @Update("UPDATE verification_code SET code = #{code}, created_at = NOW() WHERE userPhone = #{userPhone}")
    void updateCode(@Param("userPhone") String userPhone, @Param("code") String code);

    // 查询验证码（5分钟内有效）
    @Select("SELECT code FROM verification_code WHERE userPhone = #{userPhone} AND TIMESTAMPDIFF(MINUTE, created_at, NOW()) <= 5")
    String findValidCode(@Param("userPhone") String userPhone);

    // 删除验证码
    @Delete("DELETE FROM verification_code WHERE userPhone = #{userPhone}")
    void deleteCode(@Param("userPhone") String userPhone);
}

